package com.source.labelAndBarcode.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.labelAndBarcode.entity.BarcodeRevoke;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.labelAndBarcode.vo.BarcodeRevokeVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Joey
 * @since 2021-02-23
 */
public interface BarcodeRevokeMapper extends BaseMapper<BarcodeRevoke> {

    @Select(value = "SELECT br.*, \n" +
            "su.`name` revokeName,\n" +
            "ss.`name` sendBackName,\n" +
            "stallsName\n" +
            "FROM barcode_revoke br,\n" +
            "stalls,\n" +
            "sys_user su,\n" +
            "sys_user ss\n" +
            "WHERE br.stallsId = stalls.stallsId\n" +
            "AND su.userId = br.revokePerson\n" +
            "AND ss.userId = br.sendbackPerson AND br.isDelete = 0 ")
    List<BarcodeRevokeVo> findAll();

    @Select(value = "SELECT br.*, \n" +
            "su.`name` revokeName,\n" +
            "ss.`name` sendBackName,\n" +
            "stallsName\n" +
            "FROM barcode_revoke br,\n" +
            "stalls,\n" +
            "sys_user su,\n" +
            "sys_user ss\n" +
            "WHERE br.stallsId = stalls.stallsId\n" +
            "AND su.userId = br.revokePerson\n" +
            "AND ss.userId = br.sendbackPerson AND br.isDelete = 0 ")
    IPage<BarcodeRevokeVo> findAllOnPagination(Page<BarcodeRevokeVo> page);

    @Select(value = "SELECT br.*, \n" +
            "su.`name` revokeName,\n" +
            "ss.`name` sendBackName,\n" +
            "stallsName\n" +
            "FROM barcode_revoke br,\n" +
            "stalls,\n" +
            "sys_user su,\n" +
            "sys_user ss\n" +
            "WHERE br.stallsId = stalls.stallsId\n" +
            "AND su.userId = br.revokePerson\n" +
            "AND ss.userId = br.sendbackPerson AND br.barcodeRevokeId = #{id} AND br.isDelete = 0 ")
    BarcodeRevokeVo findById(String id);

    @Select(value = "SELECT\n" +
            "\tbr.*, \n" +
            "\tsu.`name` revokeName,\n" +
            "\tss.`name` sendBackName,\n" +
            "\tstallsName \n" +
            "FROM\n" +
            "\tbarcode_revoke br,\n" +
            "\tstalls,\n" +
            "\tsys_user su,\n" +
            "\tsys_user ss \n" +
            "WHERE\n" +
            "\tbr.stallsId = stalls.stallsId \n" +
            "\tAND su.userId = br.revokePerson \n" +
            "\tAND ss.userId = br.sendbackPerson\n" +
            "\tAND CONCAT(barcodeId,br.stallsId,revokeDate,su.`name`,ss.`name`,sendbackCause) LIKE #{keyWord} " +
            "AND br.isDelete = 0 ")
    IPage<BarcodeRevokeVo> findByKeyWord(Page<BarcodeRevokeVo> page, String keyWord);
}
